<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
pc_base::load_sys_class('form', '', 0);
pc_base::load_app_func('util');
pc_base::load_sys_class('format','',0);
class sousuo extends admin {
    public function __construct() {
        parent::__construct();
        $this->db = pc_base::load_model('sousuo_model');
    }

    public function init(){
       $siteid= param::get_cookie('siteid');
        $data=$this->db->select();
        include $this->admin_tpl('sousuo');

    }

    public function add(){
        include $this->admin_tpl('sousuo_add');
    }
    public function action(){
        $siteid= param::get_cookie('siteid');
        if($_POST['act']=='add'){
		   $data['title']=$_POST['title'];
		   $data['rurl']=$_POST['rurl'];
		   $data['listorder']=$_POST['listorder'];
		   $data['inputtime']=time();
		   if($this->db->insert($data)){
			   showmessage("添加成功","index.php?m=webman&c=sousuo&a=init");
		   }else{
			   showmessage("添加失败，请稍后再试","index.php?m=webman&c=sousuo&a=init");
		   }

            exit;
        }


       if($_POST['act']=='edit'){
           $id=$_POST['id'];
           $data['rurl']=$_POST['rurl'];
           $data['title']=$_POST['title'];
           $data['listorder']=$_POST['listorder'];
           $data['updatetime']=time();
			if($this->db->update($data,"id=$id")){
				showmessage("修改成功","index.php?m=webman&c=sousuo&a=init");
			}else{
				showmessage("修改失败","index.php?m=webman&c=sousuo&a=init");
			}

           exit;
       }
    }

    public function del(){
        $id=$_POST['id'];
        if($this->db->delete("id=$id")){
            exit("ok");
        }else{
            exit("fail");
        }
    }

    public function edit(){
      echo  $id=$_POST['id'];
        $data=$this->db->get_one("id=$id");
        include $this->admin_tpl('sousuo_edit');
    }



}